package com.leorui.schoollife.mapper

import com.leorui.schoollife.entity.PhotoEntity
import org.apache.ibatis.annotations.*

@Mapper
interface IDBIcons {
    // 获取图片列表
    @Select("select icon_id, icon_src from user_icon")
    @Results(value = [
        Result(id = true, column = "icon_id", property = "iconId"),
        Result(column = "icon_src", property = "iconSrc")
    ])
    fun selectPhotoList(): List<PhotoEntity?>?

    // 添加图片
    @Insert("insert into user_icon(icon_id, icon_src) value(#{iconId},#{iconSrc})")
    fun addPhoto(@Param(value = "iconId") iconId: String, @Param(value = "iconSrc") iconSrc: String): Int?

    // 删除图片
    @Delete("delete from user_icon where icon_id = #{iconId}")
    fun deletePhoto(@Param(value = "iconId") iconId: String): Int?

    // 删除所有图片
    @Delete("delete from user_icon")
    fun deleteAllPhoto(): Int?

    @Select("select icon_id, icon_src from user_icon where icon_id = #{iconId}")
    @Results(value = [
        Result(id = true, column = "icon_id", property = "iconId")
    ])
    fun selectPhotoInfo(@Param(value = "iconId") iconId: String): PhotoEntity?

    @Select("select count(icon_id) from user_icon where icon_id = #{iconId}")
    fun isPhotoAlive(@Param(value = "iconId") iconId: String): Int?

    @Update("update user_student set icon = #{iconId} where account = #{account}")
    fun updateUserIcon(@Param(value = "account") account: String, @Param(value = "iconId") iconId: String): Int?
}